package com.ytzl.itrip.biz.controller;

import com.ytzl.itrip.beans.model.ItripAreaDic;
import com.ytzl.itrip.beans.model.ItripHotelFeature;
import com.ytzl.itrip.beans.model.ItripImage;
import com.ytzl.itrip.beans.model.ItripLabelDic;
import com.ytzl.itrip.beans.model.vo.*;
import com.ytzl.itrip.biz.service.*;
import com.ytzl.itrip.utils.common.Dto;
import com.ytzl.itrip.utils.common.DtoUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/api/hotel")
public class itripHotelController {


    @Resource
    private ItripAreaDicService itripAreaDicService;
    @Resource
    private ItripLabelDicService itripLabelDicService;
    @Resource
    private ItripImageService itripImageService;
    @Resource
    private ItripHotelService itripHotelService;

    @RequestMapping(value = "/queryhotcity/{type}",method = RequestMethod.GET,
    produces = "application/json")
    @ResponseBody
    public Dto queryhotcity(@PathVariable("type") int type) {
        Map<String,Object> param = new HashMap<>();
        param.put("isHot","1");
        param.put("isChina",type);
        List<ItripAreaDicVo> itripAreaDicVoList = new ArrayList<>();
        List<ItripAreaDic> itripAreaDics = null;
        try {
            itripAreaDics = itripAreaDicService.getListByMap(param);
            for (ItripAreaDic itripAreaDic :itripAreaDics) {
                ItripAreaDicVo itripAreaDicVo = new ItripAreaDicVo();
                BeanUtils.copyProperties(itripAreaDic,itripAreaDicVo);
                itripAreaDicVoList.add(itripAreaDicVo);
            }
            return DtoUtil.returnDataSuccess(itripAreaDicVoList);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return DtoUtil.returnFail("获取数据失败","3001");
    }

    @RequestMapping("/queryhotelfeature")
    @ResponseBody
    public Dto queryhotelfeature() {
        Map map = new HashMap();
        map.put("parentId",16);
        List<ItripLabelDicVo> itripLabelDicVos = new ArrayList<>();
        try {
            List<ItripLabelDic> itripLabelDics = itripLabelDicService.getListByMap(map);
            for (ItripLabelDic itripLabelDic:itripLabelDics){
                ItripLabelDicVo itripLabelDicVo = new ItripLabelDicVo();
                BeanUtils.copyProperties(itripLabelDic,itripLabelDicVo);
                itripLabelDicVos.add(itripLabelDicVo);
            }
            return DtoUtil.returnSuccess("查询成功",itripLabelDicVos);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return DtoUtil.returnFail("查询失败","4001");
    }

    @RequestMapping(value = "/getimg/{targetId}",method = RequestMethod.GET,
            produces = "application/json")
    @ResponseBody
    public Dto getimg(@PathVariable("targetId") String targetId){
        Map map = new HashMap();
        map.put("type","0");
       if (targetId == null || targetId ==""){
           return DtoUtil.returnFail("酒店id不能为空","100212");
       }else {
           map.put("targetId",targetId);
           List<ItripImageVo> itripImageVos = new ArrayList<>();
           try {
               List<ItripImage> itripImages = itripImageService.getListByMap(map);
               for (ItripImage itripImage:itripImages){
                   ItripImageVo itripImageVo = new ItripImageVo();
                   BeanUtils.copyProperties(itripImage,itripImageVo);
                   itripImageVos.add(itripImageVo);
               }
               return DtoUtil.returnSuccess("获取酒店图片成功",itripImageVos);
           } catch (Exception e) {
               e.printStackTrace();
               return DtoUtil.returnFail("100212","获取酒店图片失败");
           }
       }
    }

    @RequestMapping(value = "/getvideodesc/{hotelId}",method = RequestMethod.GET)
    @ResponseBody
    public Dto getvideodesc(@PathVariable("hotelId") String hotelId){
        if (hotelId!=null&&hotelId!=""){
            try {
                ItripHotelFeatureTradVo itripHotelFeatureTradVo = itripHotelService.getvideodesc(hotelId);
                return DtoUtil.returnSuccess("获取酒店视频文字描述成功",itripHotelFeatureTradVo);
            } catch (Exception e) {
                e.printStackTrace();
                return DtoUtil.returnFail("获取描述失败","100214");
            }
        }else{
            return DtoUtil.returnFail("酒店Id不能为空","100215");
        }
    }

    @RequestMapping(value = "/queryhoteldetails/{id}",method = RequestMethod.GET)
    @ResponseBody
    public Dto querydetail(@PathVariable("id") Long hotelId){
        if (hotelId!=null){
            try {
                ItripHotelDetailVo itripHotelDetailVo =
                        new ItripHotelDetailVo();
                itripHotelDetailVo.setName("酒店介绍");
                itripHotelDetailVo.setDescription(itripHotelService.getById(hotelId).getDetails());
                List<ItripHotelDetailVo> itripHotelDetailVos = itripHotelService.querydetail(hotelId);
                itripHotelDetailVos.add(0,itripHotelDetailVo);
                return DtoUtil.returnSuccess("获取酒店特色介绍成功",itripHotelDetailVos);
            } catch (Exception e) {
                e.printStackTrace();
                return DtoUtil.returnFail("系统异常，获取失败","100211");
            }
        }else{
            return DtoUtil.returnFail("酒店Id不能为空","100210");
        }
    }

    @RequestMapping(value = "/queryhotelfacilities/{hotelId}",method = RequestMethod.GET)
    @ResponseBody
    public Dto queryhotelfacilities(@PathVariable("hotelId") Long hotelId){
        if (hotelId!=null){
            try {
                return DtoUtil.returnSuccess("获取酒店设施成功",itripHotelService.getById(hotelId).getFacilities());
            } catch (Exception e) {
                e.printStackTrace();
                return DtoUtil.returnFail("系统异常，获取失败","100207");
            }
        }else{
            return DtoUtil.returnFail("酒店Id不能为空","100206");
        }
    }

    @RequestMapping(value = "/queryhotelpolicy/{hotelId}",method = RequestMethod.GET)
    @ResponseBody
    public Dto queryhotelpolicy(@PathVariable("hotelId") Long hotelId){
        if (hotelId!=null){
            try {
                return DtoUtil.returnSuccess("获取酒店政策成功",itripHotelService.getById(hotelId).getHotelPolicy());
            } catch (Exception e) {
                e.printStackTrace();
                return DtoUtil.returnFail("系统异常，获取失败","100209");
            }
        }else{
            return DtoUtil.returnFail("酒店Id不能为空","100208");
        }
    }
    @RequestMapping(value = "/querytradearea/{cityId}",method = RequestMethod.GET)
    @ResponseBody
    public Dto queryTradeArea(@PathVariable("cityId") Long cityId){
        if (cityId!=null){
            try {
                return DtoUtil.returnDataSuccess(itripHotelService.querytradearea(cityId));
            } catch (Exception e) {
                e.printStackTrace();
                return DtoUtil.returnFail("系统异常，获取失败","100204");
            }
        }else{
            return DtoUtil.returnFail("酒店Id不能为空","100203");
        }
    }
}
